import { ref } from 'vue'
import { getCheckFlowTemplateList as getCheckFlowTemplateListApi } from '@/api/basic'

/**
 * 获取流程模板列表服务
 */
export default function () {
  const getCheckFlowTemplateListLoading = ref(false)
  const checkFlowTemplateList = ref<Array<BaseInfoAPIResponse.CheckFlowTemplateListItem>>([])

  const getCheckFlowTemplateList = async () => {
    try {
      getCheckFlowTemplateListLoading.value = true
      const res = await getCheckFlowTemplateListApi()
      getCheckFlowTemplateListLoading.value = false
      if (res.data.code === 20000) {
        checkFlowTemplateList.value = res.data.data.data
        return ''
      }

      return res.data.message
    } catch (error) {
      getCheckFlowTemplateListLoading.value = false
      return '获取流程模板列表失败，请稍后重试'
    }
  }

  return {
    checkFlowTemplateList,
    getCheckFlowTemplateListLoading,
    getCheckFlowTemplateList,
  }
}
